<?php
class AttrValueFormModel extends Model{
	public $table = 'attr_class';
	public function specForm($gtid){
		$attrData = $this->where(array('gt_id'=>$gtid,'is_spec'=>'1'))->all();
		if(empty($attrData))return;
		foreach ($attrData as $n => $attrd) {
			$function = $attrd['show_type'];
			$attrValueData = $this->$function($attrd['ac_id']);
			$attrData[$n]['html'] = $attrValueData;
		}
		return $attrData;
	}

	public function dropdown($acid){
		$attrValue = M('attr_value')->where(array('ac_id'=>$acid))->all();
		$name = $attrValue[0]['ac_id'];
		$html = "<select name='spec[gg][{$name}][]'>";

		foreach ($attrValue as $n => $v) {
			$html.="<option value='".$v['av_id']."|".$v['attr_value']."'>".$v['attr_value']."</option>";
		}
		$html.= "</select>";
		return $html;
	}
	public function text($acid){

		$attrValue = M('attr_value')->where(array('ac_id'=>$acid))->all();
		// $name = $acid."|".$attrValue[0]['av_id'];
		$html = "<input type='text' name='spec[]' value='".$attrValue[0]['attr_value']."'/>";
		return $html;
	}
}
?>
